package com.smartfast4j.springboot.mybatis.demo.controller;

import com.smartfast4j.springboot.mybatis.demo.pojo.Account;
import com.smartfast4j.springboot.mybatis.demo.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * restful api来展示
 * Created by gacl on 2017/11/17.
 */
@RestController
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountService accountService;

   @GetMapping("/list")//@GetMapping("/list")等价于@RequestMapping(value = "/list",method = RequestMethod.GET)
    public List<Account> getAccounts(){
        return accountService.selectByExample(null);
    }

    @GetMapping("/{id}")
    public  Account getAccountById(@PathVariable("id") int id){
        return accountService.selectByPrimaryKey(id);
    }

    @GetMapping("/count")
    public int count(){
        return accountService.countByExample(null);
    }
}
